package com.frxuexi.shop.viewmodel

import com.frxuexi.base.db.OrderDao
import com.frxuexi.base.mvi.BaseViewModel
import com.frxuexi.base.mvi.RequestType
import com.frxuexi.shop.intent.OrderIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

@HiltViewModel
class OrderViewModel @Inject constructor(val orderDao: OrderDao):BaseViewModel<OrderIntent>() {
    override fun handleIntent(it: OrderIntent) {
        when(it){
            is OrderIntent.getOrdersByStatus->roomRequest(flow { emit(orderDao.getOrdersByStatus(it.status)) })
            is OrderIntent.updateOrder->roomRequest(flow { emit(orderDao.updateOrder(it.orderEntity)) },RequestType.UPDATE)
        }
    }
}